package com.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.demo.entity.SysUser;
import com.demo.mapper.SysUserMapper;
import com.demo.service.ISysUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.demo.util.IdWorker;
import com.demo.util.ShiroUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.UUID;

/**
 * <p>
 * 系统用户 服务实现类
 * </p>
 *
 * @author author
 * @since 2023-02-23
 */
@Service
@Slf4j
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {

    @Override
    public SysUser findUsername(String email) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("email", email);
        SysUser sysUser = super.baseMapper.selectOne(queryWrapper);
        return sysUser;
    }

    @Override
    public void register(String username, String email, String password) {
        Map<String, String> map = ShiroUtils.registerUtil(password);
        SysUser sysUser = new SysUser();
        sysUser.setUsername(username);
        sysUser.setEmail(email);
        sysUser.setSalt(map.get("salt"));
        sysUser.setPassword(map.get("password"));
        boolean save = super.save(sysUser);
    }
}
